var mysql=require('mysql');
//建立数据库连接
var db=mysql.createConnection({
    host     : 'localhost',
    user     : 'root',
    password : 'root',
    database : 'tiantianpeiwan',
    timezone:'08:00'
});
var qlzmodule={
    'gameTypeTable': function (fn) {
        var sql = `SELECT * FROM p_game `;
        db.query(sql, function (err, data) {
            fn(err, data)
        })
    },
    'giftTypeTable': function (fn) {
        var sql = `SELECT * FROM p_giftattribute `;
        db.query(sql, function (err, data) {
            fn(err, data)
        })
    },
    'deleteTable': function (gameName,fn) {
        var sql = `DELETE from p_game WHERE G_names ='${gameName}' `;
        db.query(sql, function (err, data) {
            fn(err, data)
        })
    },
    'giftDelete': function (giftName,fn) {
        var sql = `DELETE from p_giftattribute WHERE GA_name ='${giftName}' `;
        db.query(sql, function (err, data) {
            fn(err, data)
        })
    },
    'addTableValue': function (addGameName,addGameDate,addGameImg,fn) {
        var sql = `INSERT into p_game  VALUES (null,'${addGameName}','../image/index-img/icon.png','1','1','${addGameDate}','${addGameImg}')`;
        db.query(sql, function (err, data) {
            fn(err, data)
        })
    },
    'giftAdd': function (addGiftName,addGiftDate,addGiftPrice,addGiftImg,fn) {
        var sql = `INSERT INTO p_giftattribute VALUES(null,'${addGiftPrice}','${addGiftImg}','${addGiftName}','${addGiftDate}')`;
        db.query(sql, function (err, data) {
            fn(err, data)
        })
    },
    'modifyTableValue': function (modifyName,modifyDate,modifyImg,oldModify,fn) {
        var sql = `UPDATE p_game SET G_names ='${modifyName}',G_date = '${modifyDate}', G_img = '${modifyImg}'  WHERE G_names ='${oldModify}'`;
        db.query(sql, function (err, data) {
            fn(err, data)
        })
    },
    'giftModify': function (modifyName,modifyDate,modifyImg,modifyPrice,oldModify,fn) {
        var sql = `UPDATE p_giftattribute SET GA_name ='${modifyName}',GA_date = '${modifyDate}', GA_src = '${modifyImg}',GA_price = '${modifyPrice}'  WHERE GA_name ='${oldModify}'`;
        db.query(sql, function (err, data) {
            fn(err, data)
        })
    },
    'searchValue': function (searchName,fn) {
        var sql = `select * from p_game WHERE G_names  like '%${searchName}%'`;
        db.query(sql, function (err, data) {
            fn(err, data)
        })
    },
    'giftSearch': function (searchGift,fn) {
        var sql = `select * from p_giftattribute WHERE GA_name  like '%${searchGift}%'`;
        db.query(sql, function (err, data) {
            fn(err, data)
            console.log(data)
        })
    },
};
module.exports=qlzmodule;